package com.epic.details.bank.service.impl;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.epic.common.utils.convert.ConvertList;
import com.epic.details.bank.entity.Bank;
import com.epic.details.bank.mapper.BankMapper;
import com.epic.details.bank.service.IBankService;
import com.epic.details.contact.entity.Contact;
import com.epic.supplier.dto.QueryDto;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.UUID;

@Service
public class BankServiceImpl implements IBankService {

    @Autowired private BankMapper bankMapper;
    @Override
    public IPage<Bank> selectPage(QueryDto queryDto) {
        IPage<Bank> iPage = bankMapper.selectPage(new Page<>(queryDto.getPageNum(), queryDto.getPageSize()),null);
        return ConvertList.entityPageConvertVoPage(iPage,Bank.class);
    }

    @Override
    public int insertContact(Bank bank) {
        Bank DoAddBank = new Bank();
        DoAddBank.setId(generateUniqueId());
        DoAddBank.setOwnerId(bank.getOwnerId());
        DoAddBank.setOwnerType(bank.getOwnerType());
        DoAddBank.setAccountName(bank.getAccountName());
        DoAddBank.setBankName(bank.getBankName());
        DoAddBank.setBankBranch(bank.getBankBranch());
        DoAddBank.setBankAddress(bank.getBankAddress());
        DoAddBank.setAccountNumber(bank.getAccountNumber());
        DoAddBank.setAccountType(bank.getAccountType());
        DoAddBank.setCurrency(bank.getCurrency());
        DoAddBank.setSwiftCode(bank.getSwiftCode());
        DoAddBank.setAbaRouting(bank.getAbaRouting());
        DoAddBank.setIban(bank.getIban());
        DoAddBank.setIsPrimary(bank.getIsPrimary());
        DoAddBank.setRemark(bank.getRemark());
        DoAddBank.setCreateTime(bank.getCreateTime());
        DoAddBank.setUpdateTime(bank.getUpdateTime());
        return bankMapper.insert(DoAddBank);
    }

    private String generateUniqueId() {
        return UUID.randomUUID().toString();
    }
}
